package com.xiao.permission_system.mapper;

import com.xiao.permission_system.entity.Permission;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xiao.permission_system.entity.Role;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import cn.xiao.permission_system.common.MyMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * <p>
 * 权限表 Mapper 接口
 * </p>
 *
 * @author beth
 * @since 2019-10-26
 */
@Repository
public interface PermissionMapper extends MyMapper<Permission> {
     /**
      * 分页查询
      * @param page 分页信息
      * @param wrapper 查询条件
      * @return
      */
      IPage<Permission> selectPage(Page<Permission> page, @Param(Constants.WRAPPER) Wrapper<Permission> wrapper);

     @Select("select * from sys_permission p  LEFT JOIN sys_role_permission rp ON p.id=rp.permission_id LEFT JOIN sys_role r ON r.id= rp.role_id where p.id=#{id}")
     List<Role> getRoles(String permissionId);
}
